package com.wnx.job.modules.pms.controller;


import com.wnx.job.common.api.Const;
import com.wnx.job.common.api.ResultData;
import com.wnx.job.common.mapstruct.ResumeMapper;
import com.wnx.job.modules.jms.model.JmsStudent;
import com.wnx.job.modules.jms.service.JmsStudentService;
import com.wnx.job.modules.pms.model.PmsResume;
import com.wnx.job.modules.pms.service.PmsResumeService;
import com.wnx.job.modules.rms.dto.ResumeParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.security.Principal;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangnaixing
 * @since 2021-12-17
 */
@Slf4j
@RestController
@RequestMapping("/pms/pmsResume")
@Api(tags = "ResumeController",description = "简历信息管理")
public class PmsResumeController {

    @Resource
    private PmsResumeService resumeService;
    @Resource
    private JmsStudentService studentService;


    /**
     * 获取学生简历信息
     * @return
     */
    @GetMapping("/getResume")
    @ApiOperation("获取学生简历信息")
    public ResultData<ResumeParam> getResume(Principal principal) {
        log.info("=========系统正在进行获取学生简历信息中==============");
        String account = principal.getName();
        JmsStudent student = studentService.findByAccount(account);
        ResumeParam resume = resumeService.findByStudentId(student.getId());
        log.info("=========系统成功获取学生简历信息成功！！！！==============");
        return ResultData.success(Const.QUERY_RESUME_SUCCESS,resume);
    }

    /**
     * 修改简历
     * @param resumeParam
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改简历")
    public ResultData<String> update(@Valid @RequestBody ResumeParam resumeParam, Principal principal){
        log.info("=========系统正在进行修改简历中==============");

        //属性复制
        PmsResume tbResume = ResumeMapper.INSTANCE.toPojo(resumeParam);

        //设置学生ID进简历属性
        String account = principal.getName();
        JmsStudent student = studentService.findByAccount(account);
        tbResume.setStudentId(student.getId());

        resumeService.updateById(tbResume);
        log.info("=========系统成功修改简历成功！！！！==============");
        return ResultData.success(Const.UPDATE_RESUME_SUCCESS);

    }

    /**
     * 修改简历状态
     * @param paramMap
     * @return
     */
    @PostMapping("/updateJobStatus")
    @ApiOperation("修改简历状态")
    public ResultData<String> updateJobStatus(@RequestBody Map<String,Object> paramMap, Principal principal){
        log.info("=========系统正在进行修改简历状态中==============");

        //获取简历信息
        String account = principal.getName();
        JmsStudent student = studentService.findByAccount(account);
        ResumeParam resumeParam = resumeService.findByStudentId(student.getId());

        //属性复制
        PmsResume tbResume = ResumeMapper.INSTANCE.toPojo(resumeParam);
        //设置工作状态进到简历中
        String jobStatus = (String) paramMap.get("jobStatus");
        tbResume.setJobStatus(jobStatus);
        resumeService.updateById(tbResume);

        log.info("=========系统修改简历状态成功！！！！==============");
        return ResultData.success(Const.UPDATE_RESUME_SUCCESS);
    }


    /**
     * 根据简历ID获取简历详情
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @ApiOperation("根据简历ID获取简历详情")
    public ResultData<ResumeParam> findById(@PathVariable(name = "id")Long id){
        log.info("==========系统正在根据简历ID获取简历详情中==============");

        //调用服务层根据简历ID，获取简历详情
        ResumeParam resume =   resumeService.findDetailById(id);


        log.info("==========系统根据简历ID获取简历详情成功==============");
        return ResultData.success(Const.QUERY_RESUME_SUCCESS,resume);

    }

}

